<?php

class MultiSelect extends PageElement
{
	private $options = array();
	private $size=1;
	private $selectedOptions = array();

	private function isSelected($item)
	{
//		echo $item." ";
//		print_r ($this->selectedOptions);
		foreach($this->selectedOptions as $anOption)
		{
			if($anOption == $item) return true; 
		}
		return false;
	}

	public function __construct()
	{
	}

	public function setName($name)
	{
		$this->name = $name."[]";
	}

	public function setSize($Size)
	{
		$this->size = $Size;
	}

	public function setOptions($Options)
	{
		$this->options = $Options;
	}

		public function setSelected($arrSelected)
	{
		$this->selectedOptions =  $arrSelected;
	}

	public function addOption($DDLOption)
	{
		array_push($this->options,$DDLOption);
	}

	public function getHTML()
	{
		$html = "<select".parent::getHTML()." multiple size=\"".$this->size."\">\n";


		foreach($this->options as $option)
		{
			$selectedText = "";
			if(MultiSelect::isSelected($option->getValue()))
			{
				$selectedText = " selected";
			}
			$html .= "<option value=\"".$option->getValue()."\"".$selectedText.">".$option->getText()."</option>\n";
		}
		$html .= "</select>\n";
		return $html;
	}

}
?>
